<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
// 网站地址
String netPath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
%>
<!doctype html>
<head>
<meta charset="utf-8">
<title>更新栏目弹出层</title>
<link href="<c:url value="/stylesheets/common.css"/>" rel="stylesheet" type="text/css" />
<link href="<c:url value="/stylesheets/account.css"/>" rel="stylesheet" type="text/css" />
<script  src="<c:url value="/javascripts/jquery.js"/>"></script>
<style>
.role_form{padding:20px 0 0 10px;}
.role_form .jsmc,.role_form textarea{width:320px;}
.linkhand { cursor: pointer;}
</style>
<script type="text/javascript">

/**
 *	提交之前的校验
 */
function validateSubmit(obj){
	var message = "";
	$("[data-required='true']").each(function(){
		var value = $(this).val();
		if(!value){
			var nullMessage = $(this).attr("null-message");
			message += nullMessage+"\n";
		}
	});
	if(message){
		alert(message);
		return false;
	}else{
		return true;
	}
};

// 获得栏目id
function setColumn(){

	// 最后一个
	var seletedCol = $("select[name=selectedCol] option[selected]:last");
	var colID = seletedCol.val();
	if(colID==undefined){
		alert("获取栏目失败");
	} else {
		$("#cid").val(colID);
		//alert($("#cid").val());
	}
};

/**
 * 增加栏目
 */
 function update(obj){

    // 更新前检查
 	if(validateSubmit(obj)){
 	
 		setColumn();
 		
 		// 增加栏目
 		$.ajax({
			  url: "<%=basePath%>column/toUpdate",
			  type:"POST",
			  contentType:"application/x-www-form-urlencoded; charset=utf-8",
			  data: $("#addColumnForm").serialize(),
			  dataType: 'text',
			  success: function(data) {
				 var jsonobj=eval('('+data+')');
				 if(jsonobj.state==='1'){
				 	alert(jsonobj.result);
					refreshColumns();
					parent.$.dialog.close();
				 } else if(jsonobj.state==='0'){
					 alert(jsonobj.result);
				 }
			  },
			  error: function(XMLHttpRequest, textStatus, errorThrown) {
					 alert("更新栏目失败！");
			  }
			});
 	}

};

//刷新栏目
function refreshColumns(){
	parent.$(".userContent").load("<%=basePath%>column/showColumns",function(response,status){
  			if (status=="success"){
  				var intPageSum = parseInt($(response).find("input[name='pageSum']").val());
  				if(intPageSum>1){
  					pageSum = intPageSum;
  				}
  				initPageButton();
  			}
	});;
}
</script>
</head>

<body>
<div class="role_form">
<form:form modelAttribute="menuColumn"  action="/column/toAdd" method="post" id="addColumnForm">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="jsgltable mt10">
  <tr>
    <td width="15%" valign="top"><p>栏目名字：</p></td>
    <td width="85%" valign="top">
      <input type="hidden" name="id" value="${menuColumn.id}">
      <input name="name" type="text" id="textfield" value="${menuColumn.name}"  data-required="true"  null-message="栏目名称不能为空 ！" placeholder="输入您要创建的栏目名称" class="jsmc">
     </td>
  </tr>
  <tr>
    <td valign="top"><p>父亲栏目：</p></td>
    <td valign="top">
    	<!-- 1级必有，2级有显示，无则隐藏   3级如2级   -->
        <span class="columnChosen">
         		<script type="text/javascript">

         			$.ajaxSetup ({ cache: false });
         			var parentId = "${menuColumn.parentId}";
         			if(parentId==""){
         				parentId = "-1";
         			}
         			$(".columnChosen").load("<%=basePath%>/column/loadParentColumn/"+parentId);
         		</script>
         </span>
         <!-- 栏目ID -->
         <input type="hidden" name="parentId" id="cid" value="${menuColumn.parentId}"/>
    </td>
  </tr>
  <tr>
    <td valign="top"><p>排序：</p></td>
    <td width="85%" valign="top">
      <input name="sortWay" type="text" id="textfield" class="jsmc" value="${menuColumn.sortWay}">
      <!-- 类型隐藏 -->
      <input name="menuType" type="hidden" id="textfield"  class="jsmc" value="0">
     </td>
  </tr>
<!--   <tr>
    <td valign="top"><p>栏目类型：</p></td>
    <td width="85%" valign="top">
    	<input name="menuType" type="hidden" id="textfield"  class="jsmc" value="0">(0:普通栏目    1-6：重点展示区域)
     </td>
  </tr>  -->
</table>
 <div class="btnblock ">
        <input name="Input" type="button" value="修改" onclick="update(this)" class="btngreen01 linkhand"/>
 </div>
 </form:form>
</div>
</body>
</html>
